<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('调度任务')" />
</head>
<body class="gray-bg">
  <div class="container-div">
    <div class="row">
      <div class="col-sm-12 select-table table-striped">
        <table id="bootstrap-table"></table>
      </div>
    </div>
  </div>

  <div th:include="include :: footer"></div>
  <script th:inline="javascript">
    var executeStates = [[${@disjobService.enums('ExecuteState')}]];
    var stateMap = {10: "info", 20: "success", 30: "warning", 40: "primary", 50: "danger"};

    $(function () {
      var options = {
        data: [(${tasks})],
        sidePagination: "client",
        showSearch: false,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        columns: [{
          field: 'taskId',
          title: 'TaskId'
        },
        {
          field: 'taskNo',
          title: '任务序号'
        },
        {
          field: 'taskParam',
          title: '任务参数',
          formatter: function (value, row, index) {
            return $.table.tooltip(value, 30, "open");
          }
        },
        {
          field: 'executeStartTime',
          title: '执行开始时间'
        },
        {
          field: 'executeEndTime',
          title: '执行结束时间'
        },
        {
          field: 'executeDuration',
          title: '执行时长(秒)',
          formatter: function (value, row, index) {
            if (value === 0) {
              return "0";
            }
            return value ? parseFloat((value / 1000).toFixed(2)) : "-";
          }
        },
        {
          field: 'executeState',
          title: '执行状态',
          formatter: function (value, row, index) {
            var label = $.table.selectData(executeStates, value, 'value', 'desc');
            return $.common.sprintf("<span class='badge badge-%s'>%s</span>", stateMap[value > 50 ? 50 : value], label);
          }
        },
        {
          field: 'executeSnapshot',
          title: '执行结果',
          formatter: function (value, row, index) {
            return $.table.tooltip(value, 30, "open");
          }
        },
        {
          field: 'worker',
          title: '执行机器',
          formatter: function (value, row, index) {
            return $.table.tooltip(value, 20, "open");
          }
        },
        {
          field: 'errorMsg',
          title: '异常信息',
          formatter: function (value, row, index) {
            return $.table.tooltip(value, 30, "open");
          }
        }]
      };
      $.table.init(options);
    });
  </script>

</body>
</html>
